﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WF_AppFuel.Validation
{
    /// <summary>
    /// Utility class containing common regular expression patterns.
    /// </summary>
    /// <author>Arjay C. Nacion</author>
    public static class RegexUtil
    {
        /// <summary>
        /// Regular expression pattern string for validating Emails.
        /// </summary>
        public static string EMAIL_PATTERN 
        {
            get
            {
                return @"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
                    + @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
                    + @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
                    + @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$";
            }
        }

        /// <summary>
        /// Regular expression pattern string for validating UK Telephone Numbers
        /// </summary>
        public static string UK_TELEPHONE_PATTERN 
        {
            get
            {
                return @"(\s*\(?0\d{4}\)?(\s*|-)\d{3}(\s*|-)\d{3}\s*)"
                    + @"|(\s*\(?0\d{3}\)?(\s*|-)\d{3}(\s*|-)\d{4}\s*)"
                    + @"|(\s*(7|8)(\d{7}|\d{3}(\-|\s{1})\d{4})\s*)";
            }
        }

        /// <summary>
        /// Regular expression pattern string for validating US or Canadian Telephone Numbers.
        /// </summary>
        public static string US_OR_CANADIAN_TELEPHONE_PATTERN 
        {
            get { return @"^[01]?[- .]?\(?[2-9]\d{2}\)?[- .]?\d{3}[- .]?\d{4}$"; }
        }

        /// <summary>
        /// Regular expression pattern string for validating DateTime strings.
        /// </summary>
        public static string DATE_TIME_PATTERN
        {
            get
            {
                return @"^(?=\d)(?:(?:31(?!.(?:0?[2469]|11))"
                  + @"|(?:30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]"
                  + @"|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])"
                  + @"|(?:(?:16|[2468][048]|[3579][26])00)))(?:\x20|$))"
                  + @"|(?:2[0-8]|1\d|0?[1-9]))([-./])(?:1[012]|0?[1-9])\1(?:1[6-9]"
                  + @"|[2-9]\d)?\d\d(?:(?=\x20\d)\x20|$))?(((0?[1-9]|1[012])"
                  + @"(:[0-5]\d){0,2}(\x20[AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$";
            }
        }

        /// <summary>
        /// Regular expression pattern sting for validating IP Addresses.
        /// </summary>
        public static string IP_ADDRESS_PATTERN
        {
            get
            {
                return @"^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}"
                    + @"|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]"
                    + @"|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}"
                    + @"|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}"
                    + @"|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]"
                    + @"|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$";
            }
        }
    }
}
